package com.springsecurity.controllers;

import com.springsecurity.data.constants.UserDetailsConstants;
import com.springsecurity.data.domains.ObjectType;
import com.springsecurity.data.repositories.ObjectTypeRepository;
import com.springsecurity.model.common.ModelObject;
import com.springsecurity.model.users.Account;
import com.springsecurity.services.AccountService;
import com.springsecurity.services.ModelObjectsService;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.context.WebContext;
import org.thymeleaf.spring3.SpringTemplateEngine;

/**
 *
 * @author Evgeny Obednin
 */
@Controller
public class TestController {

    @Autowired
    private ObjectTypeRepository otRepository;
    
    @Autowired
    private AccountService authService;

    @ModelAttribute("attttr")
    public String prepareAtttttrModel() {
        String str = "";
        for (ObjectType ot : otRepository.findAll()) {
            str += ot.getName() + "; ";
        }  
        return str;
    }
    
    @ModelAttribute("account")
    public Account prepareAccountModel() {
        return authService.getAccountByLogin("user");
    }
    
//    @RequestMapping(value = "/test")
//    public ModelAndView goToTestPage() {
//        ModelAndView view = new ModelAndView();
//        view.setViewName("test");
//
//        //if(true) throw new RuntimeException(str);
//        
////        String str = "MVC Spring is here!";
//
//        return view;
//    }
    
    @RequestMapping(value = "/test")
    public String goToTestPage() {
        //prepareAtttttrModel();
        prepareAccountModel();
        return "test";
    }
    

}
